package interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import cn.johnyu.util.WebServiceUtil;

public class BlackMerchantInterceptor extends HandlerInterceptorAdapter {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		Map pathVariables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
		String mid = (String) pathVariables.get("mid");
		String status = WebServiceUtil.merchantStatus(mid);
		if(status.equals("1")){
			return true;
		}else{
			response.sendRedirect(request.getContextPath() + "/index");
			return false;
		}
	}
}
